package se.lth.student.axisandroidcam.client;

import java.util.Observable;
import java.util.Observer;

import javax.tools.Tool;

import android.text.style.UpdateAppearance;

import se.lth.cs.fakecamera.Axis211A;
import se.lth.student.axisandroidcam.client.cameraclients.ClientIn;
import se.lth.student.axisandroidcam.client.cameraclients.ClientOut;
import sun.security.action.GetIntegerAction;

public class Camera {
	public int cameraNbr, cameraType;
	private byte[] pic;
	private PrivateObserver observer;

	
	public Camera(int cameraNbr){
		this.cameraNbr = cameraNbr;
		observer = new PrivateObserver();

	}
	
	
	public synchronized void setPicture(byte[] data, boolean isMovie){
		Toolbox.printDebug("IMAGE NOW ON CAMERA!");
		pic = new byte[data.length];
		observer.update(data, isMovie);
	}
	
	
	private class PrivateObserver extends Observable{
	    
		public void update(byte[] data, boolean isMovie){
			DataWrapper wrapper = new DataWrapper(data, Camera.this.cameraNbr, isMovie);
			setChanged();
			notifyObservers(wrapper);
		}
		public void update(byte[] data){
			DataWrapper wrapper = new DataWrapper(data, Camera.this.cameraNbr, false);
			setChanged();
			notifyObservers(wrapper);
		}
	}
	
	public void associateWithObserver(Observer obs){
		observer.addObserver(obs);
	}
	
	public int getId(){
		return cameraNbr;
	}	
}
